//
//  ProfileTableViewController.m
//  Copy_AiKapPu_Personal_OC
//
//  Created by taojianz on 2017/7/10.
//  Copyright © 2017年 taojianz. All rights reserved.
//

#import "ProfileTableViewController.h"

@interface ProfileTableViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;
@property (strong,nonatomic) UIImageView* barImageView;
@property (assign,nonatomic) CGFloat originalHeight;

@end

@implementation ProfileTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    self.tableView.delegate = self;
    self.originalHeight = self.headerImageView.frame.size.height+32;
    
    // FIXME: 完成设置的点击事件
    UIImage *itemImage = [UIImage imageNamed:@"32-设置"];
    UIImage *originImage = [itemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:originImage style:UIBarButtonItemStylePlain target:self action:nil];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    
    NSLog(@"%@",NSStringFromCGRect(self.headerImageView.frame));
 }

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint point = scrollView.contentOffset;
    // 最初的tableView。offset = -64 因为存在navigationBar
    if (point.y < -64) {
        CGRect rect = self.headerImageView.frame;
        
        rect.origin.y = point.y;
        // 改变图片的frame但是保证用户所看到的部分大小不改变
        rect.size.height = -point.y+self.originalHeight;
//        NSLog(@"%@",NSStringFromCGRect(rect));
        // 由于我设置的图像模式时aspectFill 所以虽然看起来显示的比较多但是imageView是比较小的，故要不改变用户所观察到的图片应该有所偏差，这个偏差要自己去计算
        self.headerImageView.frame = rect;
    }
    
    
}





@end
